1. Field Of The Invention
The present invention relates generally to a microcomputer system, and more particularly to, a method of handling stack related errors of a microprocessor in a microcomputer system.
2. Description Of Related Art
Commonly, a microcomputer system includes a microprocessor unit (MPU) having at least one internal register such as a stack pointer. The stack pointer is typically a 16-bit (two-byte) register that contains a beginning address, normally in random access memory (RAM), where the status of the MPU registers may be stored when the MPU has other functions to perform, such as during an interrupt or during a branch to subroutine. The address in the stack pointer is the starting address of sequential memory locations in RAM, where MPU contents of the registers will be stored. Typically, the MPU will execute instructions at a new location that contains the subroutine. When this subroutine is over, a return from subroutine (RTS) instruction is encountered. This tells the MPU that there are no more instructions in the subroutine and that it should return to the main program at its original address.
In general, problems sometimes occur in the use of a return address by a subroutine as retained in the stack pointer or RAM of the microcomputer. More specifically, when a subroutine is utilized, a return address from the main program is written into a memory address in the stack pointer so that the subroutine will know which section of the main program to return to after finishing its job. At the end of the subroutine, the subroutine will employ a return from subroutine instruction and read the return address that was stored at the beginning of the subroutine. At this point, the microprocessor would load the return address from the stack pointer and return to the main program at that memory address location or at that point in the main program.
A problem which is common in this type of programming is that the subroutines can be written by many individuals and could contain an error. One of the most common errors that appears in such subroutines is the use of an indirect indexed address and other stack manipulation instructions which involve pointing toward a memory address location and confusing the contents of a memory address location with the memory address itself. It can readily be seen that if the memory address is confused with the actual contents of the memory location that significant error could occur and that the program could be sent to an address that was either a wrong address or a piece of data. This is what is commonly referred to as a "bug". This type of situation also is readily apparent in the use of programs on an interrupt basis as combined with a stack pointer or traditional stack pointer type of program or which operate on an interrupt only basis.